package com.android.hedgehog;

import java.util.List;

import android.graphics.Color;

import com.android.hedgehog.FreePlayMenu.page;
import com.android.hedgehog.framework.Game;
import com.android.hedgehog.framework.Graphics;
import com.android.hedgehog.framework.Screen;
import com.android.hedgehog.framework.Input.TouchEvent;

public class LevelSelect extends Screen {
	enum Page {
		Page1, Page2
	}

	Graphics graphics;
	int roundReached;
	Page currentPage;

	public LevelSelect(Game game) {
		super(game);
		graphics = game.getGraphics();
		roundReached = Settings.round;
		currentPage = Page.Page1;
	}

	@Override
	public void update(float deltaTime) {
		List<TouchEvent> touchEvents = game.getInput().getTouchEvents();
		game.getInput().getKeyEvents();

		int len = touchEvents.size();
		for (int i = 0; i < len; i++) {
			TouchEvent event = touchEvents.get(i);
			if (event.type == TouchEvent.TOUCH_UP) {

				if (currentPage == Page.Page1) {// PAGE1

					if (event.y > 5 && event.y < 75) {
						playSound(1);
					}
					if (event.y > 85 && event.y < 155) {
						if (roundReached >= 1)
							game.setScreen(new VersesScreen(game, 0));
						playSound(1);
					}
					if (event.y > 165 && event.y < 235) {
						if (roundReached >= 2)
							game.setScreen(new BattleScreen(game, 2));

					}
					if (event.y > 245 && event.y < 320) {

					}
					if (event.y > 330 && event.y < 400) {

					}

					if (event.x < 50 && event.y > 430) { // if back button
						playSound(1);
						game.setScreen(new MainMenu2(game));
						return;
					}
					if (event.x > 270 && event.y > 430) { // if Forward button
						playSound(1);
						currentPage = Page.Page2;
						return;
					}

				}// PAGE1

				if (currentPage == Page.Page2) { // PAGE2

					if (event.y > 5 && event.y < 75) {
						// if(roundReached>=5)
						// game.setScreen(new BattleScreen(game, 5));
						playSound(1);
					}
					if (event.y > 85 && event.y < 155) {
						playSound(1);
					}
					if (event.y > 165 && event.y < 235) {

					}
					if (event.y > 245 && event.y < 320) {

					}
					if (event.y > 330 && event.y < 400) {

					}

					if (event.x < 50 && event.y > 430) { // if back button
						playSound(1);
						currentPage = Page.Page1;
						return;
					}

				}// PAGE2

			} // TOUCH UP
		}

	}

	@Override
	public void present(float deltaTime) {
		graphics.drawBackground(Color.BLACK);

		if (currentPage == Page.Page1) { // PAGE1

			for (int i = 0; i < 5; i++) {
				if (i <= roundReached) {
					graphics.drawUniversalRect(0, 5 + (80 * i), 319, 70, false, false, 4, 255, Color.YELLOW); // rectangle
					if (i == 0) {
						graphics.drawUniversalText("INSTRUCTIONS", 2, true, 160, 60, 38, 255, Color.MAGENTA);
					}
					if (i == 1) {
						graphics.drawUniversalText("VS LOGIC-BOT", 2, true, 160, 140, 38, 255, Color.MAGENTA);
					}
					if (i == 2) {
						graphics.drawUniversalText("VS WINDOWSBOT", 2, true, 160, 220, 38, 255, Color.MAGENTA);
					}
					if (i == 3) {

					}
					if (i == 4) {

					}
				} else {
					graphics.drawUniversalRect(0, 5 + (80 * i), 319, 70, false, false, 4, 255, Color.DKGRAY); // rectangle
					graphics.drawUniversalText("?????", 2, true, 160, 60 + (i * 80), 38, 255, Color.DKGRAY);
				}
			}
			graphics.drawRect(0, 430, 50, 50, Color.WHITE);
			graphics.drawRect(270, 430, 50, 50, Color.WHITE);
		} // PAGE1

		if (currentPage == Page.Page2) { // PAGE2

			for (int i = 0; i < 5; i++) {
				if (i + 5 <= roundReached) {
					graphics.drawUniversalRect(0, 10 + (80 * i), 319, 70, false, false, 4, 255, Color.YELLOW);
					if (i == 0) {
						graphics.drawUniversalText("VS INTELPUPPY", 2, true, 160, 60, 38, 255, Color.MAGENTA);
					}
					if (i == 1) {
						graphics.drawUniversalText("VS LINUXRODENT", 2, true, 160, 140, 38, 255,
								Color.MAGENTA);
					}
					if (i == 2) {
						graphics.drawUniversalText("VS MACBOT", 2, true, 160, 220, 38, 255, Color.MAGENTA);
					}
					if (i == 3) {

					}
					if (i == 4) {

					}
				} else {
					graphics.drawUniversalRect(0, 5 + (80 * i), 319, 70, false, false, 4, 255, Color.DKGRAY);
					graphics.drawUniversalText("?????", 2, true, 160, 60 + (i * 80), 38, 255, Color.DKGRAY);
				}
			}
			graphics.drawRect(0, 430, 50, 50, Color.WHITE);
		} // PAGE2

		graphics.drawSpecialText("round: " + Settings.round, 160, 160, 18, 2, Color.BLUE);// TEST

	}

	private void playSound(int soundNum) {
		if (!Settings.soundEnabled)
			return;
		if (soundNum == 1)
			Assets.bitten.play(1);

	}

	@Override
	public void pause() {
		// TODO Auto-generated method stub

	}

	@Override
	public void resume() {
		// TODO Auto-generated method stub

	}

	@Override
	public void dispose() {
		// TODO Auto-generated method stub

	}

}
